const loginData = require('../fixtures/login.json')

export const login = () => {
  if (Cypress.env('environment') === 'local') {
    // 本地快速跳过登录步骤
    cy.visit('/login')
    cy.setCookie('_authing_token', loginData._authing_token)
    cy.visit('/console/626908881904d60cb3a87284')
    // choiceUserPool()
  } else {
    cy.login()
  }
}

export const choiceUserPool = () => {
  cy.fixture('login').then((data) => {
    cy.xpath(`//*[contains(text(),"${data.userPool}")]`).click()
  })
}

export const visitUrl = (toUrl) => {
  cy.url().then((url) => {
    let regex = /https:\/\/console.authing.cn\/console\/(.*?)\/|\w{24}/g
    let baseUrl = url.match(regex)[0]
    baseUrl = baseUrl.length === 24 ? url + '/' : baseUrl
    cy.visit(baseUrl + toUrl)
  })
}
